package cn.jc.myfile.filework.service.impl;

import cn.jc.myfile.common.entity.result.RCode;
import cn.jc.myfile.common.exception.GlobalException;
import cn.jc.myfile.common.util.FileUtil;
import cn.jc.myfile.filework.service.IFileWorkService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class FileWorkServiceImpl implements IFileWorkService {

    /**
     * 读取对应路径下的所有文件路径
     * @param rootPath
     * @return
     */
    @Override
    public List<String> queryFilePathList(String rootPath) {
        log.info("正在读取目录【{}】下的所有文件路径...", rootPath);
        List<String> filePaths;
        try {
            filePaths = FileUtil.getAllFilePaths(new File(rootPath));
        } catch (Exception e) {
            throw new GlobalException(RCode.ERROR, e.getMessage());
        }

        log.info("路径读取完毕！");
        return filePaths;
    }
}
